﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using DTO;
using System.Data.SqlClient;
using System.Data;
using System.Windows.Forms;
using System.Threading;

namespace DAO
{
    public class HopMonAnDAO
    {
        public List<HopMonAnDTO> LayHopMonAnTheoMa(int ma)
        {
            List<HopMonAnDTO> listKH = new List<HopMonAnDTO>();
            SqlConnection conn = null;
            SqlDataReader reader = null;
            try
            {
                String sql = "Select * from HopMonAn Where ID_MonAn = " + ma;

                conn = DataProvider2.ConnectDB();
                SqlCommand cm = new SqlCommand(sql, conn);
                reader = cm.ExecuteReader();
                while (reader.Read())
                {
                    HopMonAnDTO hmaDTO = new HopMonAnDTO();
                    hmaDTO.ID_Hop = reader.GetInt32(0);
                    hmaDTO.ID_MonAn = reader.GetInt32(1);

                    listKH.Add(hmaDTO);
                }
            }
            catch (Exception ex)
            { String e = ex.ToString(); }
            finally
            { conn.Close(); }
            return listKH;
        }
        public DataTable LayHopMonAnTheoMa2(int id)
        {
            //DataTable dt = new DataTable();
            SqlConnection conn = null;
            string sql = "SELECT * FROM HopMonAn WHERE ID_MonAn = " + id + "";
            conn = DataProvider2.ConnectDB();
            SqlCommand cmd = new SqlCommand(sql, conn);
            DataTable dt = new DataTable();
            dt.Load(cmd.ExecuteReader());
            conn.Close();
            return dt;
        }

        //public DataTable LayHopMonAnTheoMa2(int id, int chedo)
        //{
        //    //DataTable dt = new DataTable();
        //    SqlConnection conn = null;
        //    string sql = "SELECT * FROM HopMonAn WHERE ID_MonAn = " + id + "";
        //    conn = DataProvider2.ConnectDB(chedo);
        //    SqlCommand cmd = new SqlCommand(sql, conn);
        //    DataTable dt = new DataTable();
        //    dt.Load(cmd.ExecuteReader());
        //    conn.Close();
        //    return dt;
        //}
    }
}
